package com.emode.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.emode.base.BaseDaoImpl;
import com.emode.base.Pager;
import com.emode.entity.TopicV;
import com.emode.service.TopicVService;

public class TopicVServiceImpl extends BaseDaoImpl<TopicV> implements TopicVService{
	private static Logger logger = Logger.getLogger(TopicVServiceImpl.class);  
	@Override
	public List<TopicV> findTopicVwithPage(Serializable id, Pager p) {
		if(id==null){
			throw new RuntimeException("条件查询为空！");
		}
		//组织条件查询
		String whereHql = "";
		//定义封装的条件查询
		List valueList = new ArrayList();
		if(id!=null){
		 	whereHql = " and tsid = ?";
			valueList.add(id);
		}
		Object[] values = valueList.toArray();
		//排序
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		orderby.put("o.ttime","desc ");
		return findObjectByConditionWithPage(whereHql, values, orderby, p);
	}
	@Override
	public List<TopicV> latestTopicV(Pager p) {
		//通过发帖时间和最新回复确定topic的排序
		String hql = "FROM TopicV t ORDER BY t.tlastReply";
		return PageQuery(hql, p);
	}
	
	
	
}
